<?php

use think\migration\Migrator;
use think\migration\db\Column;
use Phinx\Db\Adapter\MysqlAdapter;

class CreateSystemLogTable extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
     /**
     * Migrate Up.
     */
    public function up()
    {
        $table = $this->table('system_log', ['engine' => 'InnoDB', 'collation' => 'utf8_general_ci', 'comment' => '' ,'id' => 'id' ,'primary_key' => ['id']]);
        $table->addColumn('uid', 'string', ['limit' => 36,'null' => true,'signed' => true,'comment' => '用户id',])
            ->addColumn('userinfo', 'text', ['limit' => MysqlAdapter::TEXT_REGULAR,'null' => true,'signed' => true,'comment' => '请求页面',])
            ->addColumn('client_ip', 'string', ['limit' => 36,'null' => true,'signed' => true,'comment' => '客户端ip',])
            ->addColumn('client_iparea', 'string', ['limit' => 100,'null' => true,'signed' => true,'comment' => 'ip地址',])
            ->addColumn('api', 'string', ['limit' => 50,'null' => true,'signed' => true,'comment' => '访问路径',])
            ->addColumn('referer', 'string', ['limit' => 300,'null' => true,'signed' => true,'comment' => '请求页面',])
            ->addColumn('token', 'text', ['limit' => MysqlAdapter::TEXT_REGULAR,'null' => true,'signed' => true,'comment' => '当前token',])
            ->addColumn('cookie', 'text', ['limit' => MysqlAdapter::TEXT_REGULAR,'null' => true,'signed' => true,'comment' => '请求cookie',])
            ->addColumn('param', 'text', ['limit' => MysqlAdapter::TEXT_REGULAR,'null' => true,'signed' => true,'comment' => '访问参数',])
            ->addColumn('result', 'text', ['limit' => MysqlAdapter::TEXT_REGULAR,'null' => true,'signed' => true,'comment' => '返回结果',])
            ->addColumn('status', 'boolean', ['null' => true,'signed' => true,'comment' => '返回状态: 0失败,1成功',])
            ->addColumn('create_time', 'timestamp', ['null' => true,'signed' => true,'comment' => '创建时间',])
            ->addIndex(['uid'], ['name' => 'uid'])
            ->addIndex(['referer'], ['name' => 'referer'])
            ->create();
    }

    /**
     * Migrate Down.
     */
    public function down()
    {
        $this->dropTable('system_log');
    }
    
}
